package toubiao.domain.po.business;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import toubiao.domain.en.ProjectType;

@Entity
@Table(name = "project")
@DynamicUpdate(true)
public class PoProject {
	
	private Long id;
	
	private Integer seq;
	
	private String name;
	
	private String type;//设计/咨询
	
	//private ProjectType projectType;
	
	private String profession;
	
	//投资金额
	private Double investAmount;
	
	/*
	@Temporal标签的作用很简单：

    (1) 如果在某类中有Date类型的属性，数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要在查询时获得年月日，在该属性上标注@Temporal(TemporalType.DATE) 会得到形如'yyyy-MM-dd' 格式的日期。

    (2)如果在某类中有Date类型的属性，数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要获得时分秒，在该属性上标注 @Temporal(TemporalType.TIME) 会得到形如'HH:MM:SS' 格式的日期。

    (3)如果在某类中有Date类型的属性，数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要获得'是'yyyy-MM-dd hh:MM:ss'，在该属性上标注 @Temporal(TemporalType.TIMESTAMP) 会得到形如'HH:MM:SS' 格式的日期
	*/
	//委托日期
	@Temporal(TemporalType.DATE)  
	private Date beginDate;
	
	private String description;

	private Set<PoProjectSn> snSet;
	
	//对应合同，多对多	
	private Set<PoContract> contractSet =new HashSet<>();
	
	//甲方：多对1
	private PoPartA partA;
	
	//甲方委托人：多对多
	private Set<PoContact> contactSet=new HashSet<>();
	
	//获奖情况:多对多
	private Set<PoReward> rewardSet =new HashSet<>();

	private Set<PoDepartment> departmentSet=new HashSet<>();
	
	private Set<PoDesigner> designerSet=new HashSet<>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	/*//@Enumerated(EnumType.STRING)//使用Value 存储到数据库
	@Enumerated(EnumType.ORDINAL)//使用 枚举的 序号
	public ProjectType getProjectType() {
		return projectType;
	}

	public void setProjectType(ProjectType projectType) {
		this.projectType = projectType;
	}*/

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	
	public String getProfession() {
		return profession;
	}

	public void setProfession(String profession) {
		this.profession = profession;
	}

	public Double getInvestAmount() {
		return investAmount;
	}

	public void setInvestAmount(Double investAmount) {
		this.investAmount = investAmount;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	@Type(type="text") 
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

/*	@ElementCollection(fetch=FetchType.EAGER, //加载策略,延迟加载  
            targetClass=Long.class) //指定集合中元素的类型  
    @CollectionTable(name="project_sn") //指定集合生成的表  
    @OrderColumn(name="seq") //指定排序列的名称  
	public List<Long> getProjectSnList() {
		return projectSnList;
	}*/

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "`project-contract`", joinColumns = { @JoinColumn(name = "project_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "contract_id", nullable = false) })
	@OrderBy("name ASC")
	public Set<PoContract> getContractSet() {
		return contractSet;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "`project-department`", joinColumns = { @JoinColumn(name = "project_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "department_id", nullable = false) })
	@OrderBy("seq ASC")
	public Set<PoDepartment> getDepartmentSet() {
		return departmentSet;
	}

	public void setDepartmentSet(Set<PoDepartment> departmentSet) {
		this.departmentSet = departmentSet;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "project")
	public Set<PoProjectSn> getSnSet() {
		return snSet;
	}

	
	public void setSnSet(Set<PoProjectSn> snSet) {
		this.snSet = snSet;
	}

	public void setContractSet(Set<PoContract> contractSet) {
		this.contractSet = contractSet;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "partA_id")
	public PoPartA getPartA() {
		return partA;
	}

	public void setPartA(PoPartA partA) {
		this.partA = partA;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "project_designer", joinColumns = { @JoinColumn(name = "project_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "designer_id", nullable = false) })
	public Set<PoDesigner> getDesignerSet() {
		return designerSet;
	}

	public void setDesignerSet(Set<PoDesigner> designerSet) {
		this.designerSet = designerSet;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "project_contact", joinColumns = { @JoinColumn(name = "project_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "contact_id", nullable = false) })
	@OrderBy("name ASC")
	public Set<PoContact> getContactSet() {
		return contactSet;
	}

	public void setContactSet(Set<PoContact> contactSet) {
		this.contactSet = contactSet;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "project_reward", joinColumns = { @JoinColumn(name = "project_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "reward_id", nullable = false) })
	@OrderBy("name ASC")
	public Set<PoReward> getRewardSet() {
		return rewardSet;
	}

	public void setRewardSet(Set<PoReward> rewardSet) {
		this.rewardSet = rewardSet;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}
}
